---@class DarkStreetButton : UIComponentInterface
DarkStreetButton = Class("DarkStreetButton",UIComponentInterface)
function DarkStreetButton:ctor(obj)
    self:OnCreate(obj)
end
function DarkStreetButton:OnCreate(obj)
    self.fguiObj = obj
    self.isCreate = true
    self.Text_TimeCount = self:GetChild("Text_TimeCount")
    self.ctrlShowTime = self:GetController("ShowTime")
    self:RegisterOnClick(self.fguiObj,self.ClickItem)
end
function DarkStreetButton:OnEnable()
    self:TimeCall(self.Update,1000,-1)
end
function DarkStreetButton:OnDisable()
    self:RemoveTimeCall(self.Update)
end
function DarkStreetButton:Refresh()
    if not logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.DarkStreet) then
        return
    end
    self.isOpenTime = nil
    self.ctrlShowTime.selectedIndex = 1
    self:TimeCall(self.Update,1000,-1)
    self:Update()
end

function DarkStreetButton:OnDestroy()
    self:DelReferenceAll()
    self.isCreate = false
end

function DarkStreetButton:ClickItem()
    FireEvent(Config.EventType.FreshDarkStreenRedDot,false)
    if not logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.DarkStreet, true, self.fguiObj) then
        return
    end
    logicMgr.DarkStreetMgr.CanEnter(true)
end

function DarkStreetButton:Update()
    local OpenStage = RedRob.Config.OpenStage
    local stage,remainTime = logicMgr.DarkStreetMgr.GetOpenStage()
    local isOpen = stage ~= OpenStage.close
    if  isOpen then
        if not self.isShowRed then
            FireEvent(Config.EventType.FreshDarkStreenRedDot,true)
            self.isShowRed = true
        end
        self.isOpenTime = true
        self.Text_TimeCount.text = string.format(getLanguage("DarkStreetTimeTips2"),HelperFunc.GetTimeStr(remainTime))
        --[[if stage == OpenStage.open then
            self.Text_TimeCount.text = string.format(getLanguage("DarkStreetTimeTips2"),HelperFunc.GetMinuteSecond(remainTime))
        else
            self.Text_TimeCount.text = string.format(getLanguage("DarkStreetTimeTips1"),HelperFunc.GetMinuteSecond(remainTime))
        end]]
    else
        self.isShowRed = false
        if self.isOpenTime or self.isOpenTime == nil then
            self.isOpenTime = false
            --self.Text_TimeCount.text = string.format(getLanguage("DarkLaneTipes_44"))
        end
        self.Text_TimeCount.text = string.format(getLanguage("DarkStreetTimeTips1"),HelperFunc.GetTimeStr(remainTime))
    end
end
return DarkStreetButton
